#import "SxwWebPlugin.h"
#import "SxwWebViewController.h"

@implementation SxwWebPlugin
+ (void)registerWithRegistrar:(NSObject<FlutterPluginRegistrar>*)registrar {
    FlutterMethodChannel* channel = [FlutterMethodChannel
                                     methodChannelWithName:@"com.sxw365.sxw_web_plugin"
                                     binaryMessenger:[registrar messenger]];
    SxwWebPlugin* instance = [[SxwWebPlugin alloc] init];
    [instance setRegistrar:registrar];
    [registrar addMethodCallDelegate:instance channel:channel];
}

- (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result {
    if ([@"open" isEqualToString:call.method]) {
        SxwWebViewController *ctl = [SxwWebViewController initWithUrl:call.arguments];
        
        UINavigationController *navi = [[UINavigationController alloc]initWithRootViewController:ctl];
        
        UIViewController *rootCtl = [[UIApplication sharedApplication].delegate.window rootViewController];
        [rootCtl presentViewController:navi animated:YES completion:nil];
        result(@"success");
    } else {
        result(FlutterMethodNotImplemented);
    }
}

@end
